//
// Created by PC on 2023/5/11.
// 位运算练习
// 2^31-1=2147483647

#include <iostream>

using namespace std;

int main()
{
//    cout<<sizeof(long long)<<endl;
    int a = 2147483647;
    //1. << 按位左移 相当于*2 >>按位右移 相当于/2
//    a = a << 1;
    cout << a << endl;
    //2. 把十进制整型转成2进制 , 用按位与&的方法
    for (int i = 31; i >=0; --i)
    {
        if (a & (1<<i))
            cout << 1;
        else
            cout << 0;
    }
    cout << endl;
    //3. 判断奇数偶数, 用按位与判断
    int c = 7;
    if ((a & 1) == 0)
        cout << "even number" << endl;
    else
        cout << "odd number" << endl;
    //4. 利用int保存数据,一个int 32bit 可以存32个数
    //4.1 存数 比如 保存年龄(0-31)
    int age = 11, store = 0, t = 1;
//    for (int j = 0; j < age; ++j)
//        t = t << 1;
    t<<=age;
    store = store | t;
    // 再存一个数
    t=1;
    age = 20;
    for (int j = 0; j < age; ++j)
        t = t << 1;
    store = store | t;
//    cout<<store<<endl;
    //4.1 取数
    cout<<"include:";
    t = 1;
    for (int i = 0; i < 32; ++i)
    {
        if(store&t)
            printf("%d ",i);
        t=t<<1;
    }
    cout<<endl;

    return 0;
}
